package com.woniuxy01;

/**
 * @author 作者
 * @create 2025-11-04 9:35
 */
public class Student implements Comparable {
    private int sid;
    private String sname;
    private int age;

    public Student() {
    }

    public Student(int sid, String sname, int age) {
        this.sid = sid;
        this.sname = sname;
        this.age = age;
    }

    public int getSid() {
        return sid;
    }

    public void setSid(int sid) {
        this.sid = sid;
    }

    public String getSname() {
        return sname;
    }

    public void setSname(String sname) {
        this.sname = sname;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "sid=" + sid +
                ", sname='" + sname + '\'' +
                ", age=" + age +
                '}';
    }

   public boolean equals(Object obj){
        if(obj instanceof Student){
            Student that=(Student)obj;
            return this.sid==that.sid
                    &&this.sname.equals(that.sname)
                    &&this.age==that.age  ;
        }
        return false;
    }

    //当前对象和参数进行比较,
    //返回值>0 this>参数
    //返回值<0 this<参数
    //返回值==0 this==参数
    @Override
    public int compareTo(Object o) {
        if(o instanceof Student){
            Student that=(Student)o;
            return (this.age-that.age);
        }
        return 1;
    }
}
